package cn.hinglo.permission.controller;

import cn.hinglo.common.annotation.RequestMapping;
import cn.hinglo.common.config.base.BaseController;
import cn.hinglo.common.interceptors.request.*;
import cn.hinglo.permission.model.Code;
import cn.hinglo.permission.service.CodeService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.paragetter.Para;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
 * @author HingLo
 * @createTime: 2020-05-18 16:48:12
 * @description: CodeController 控制器
 */
@RequestMapping("/code")
@Slf4j
public class CodeController extends BaseController {

    @Inject
    private CodeService codeService;

    /**
     * Code列表
     */
    @Before(Get.class)
    public void list(Integer page, Integer pageSize, String keyword) {
        success(codeService.listCodeService(getPage(page), getSize(pageSize), keyword));
    }

    /***
     * 添加Code 对象
     * @param code 添加的Code对象
     */
    @Before(Post.class)
    public void add(@Para("") Code code) {
        code.setGmtModified(new Date());
        success(codeService.addCodeService(code));
    }

    /***
     * 删除指定Id的Code对象
     * @param id Code编号
     */
    @Before(Delete.class)
    public void delete(Integer id) {
        success(codeService.deleteCodeService(id));
    }

    /***
     * 字典对象更新
     * @param code 字典信息
     */
    @Before(Put.class)
    public void update(@Para("") Code code) {
        code.setGmtModified(new Date());
        success(codeService.updateService(code));
    }


}
